@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>网站管理</li>
            <li class="active">财务管理</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
            红包列表
        </div>
        <div class="panel-body">
            <form class="form-horizontal" method="get" action="/admin/web/fico/giftRecords">
                <div class="form-group">
                    <label class="control-label col-sm-1">领取用户:</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" name="name"
                               value="{{($query['name']??'')}}" placeholder="请填写用户名">
                    </div>
                    <label class="control-label col-sm-1">开始时间:</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control datetimepicker" name="start_at"
                               value="{{$query['start_at']}}" placeholder="请选择开始时间">
                    </div>
                    <div class="col-sm-2">
                        <input type="text" class="form-control datetimepicker" name="end_at"
                               value="{{$query['end_at']}}" placeholder="请选择结束时间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-1">红包类型:</label>
                    <div class="col-sm-2">
                        <select name="activity_type_id" class="form-control select2">
                            <option value="">----请选择红包类型----</option>
                            <option value="gift_activity_type_1" {{$query['activity_type_id']=='gift_activity_type_1'?'selected="selected"':''}}>投资红包</option>
                            <option value="gift_activity_type_2" {{$query['activity_type_id']=='gift_activity_type_2'?'selected="selected"':''}}>现金红包</option>
                        </select>
                    </div>
                    <div class="col-sm-9 text-right">
                        <button class="btn btn-sm btn-default" type="submit">查询</button>
                        <a href="{{ admin_action('Web\FicoController@giftRecords',['download'=>'download','name'=>$query['name'],'start_at'=>$query['start_at'],'end_at'=>$query['end_at'],'activity_type_id'=>$query['activity_type_id']]) }}" class="btn btn-sm btn-primary btn-addon">
                            <i class="fa fa-download"></i>excel导出查询结果
                        </a>
                    </div>
                </div>
            </form>
            <div class="table-responsive">
                <table class="table table-striped b-t b-light">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>红包名</th>
                        <th>红包类型</th>
                        <th>红包金额</th>
                        <th>领取用户</th>
                        <th>领取时间</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    @forelse ($list as $item)
                        <tr>
                            <td>{{$item->id}}</td>
                            <td>{{$item->gift_name}}</td>
                            <td>{{empty($gift_cate[$item->activity_type])?$item->activity_type:$gift_cate[$item->activity_type]->name}}</td>
                            <td>{{$item->money}}</td>
                            <td>{{$item->name?$item->name:($item->username?$item->username:$item->phone_number)}}</td>
                            <td>{{$item->input_time}}</td>
                            <td>{{$item->status=='1'?'已使用':($item->status=='2'?'已过期':'正常')}}</td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="3" class="text-center">没有找到红包记录</td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-12 text-right text-center-xs">
                    {!! $links !!}
                </div>
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading font-bold">统计</div>
        <div class="panel-body">
             <table class="table">
                <thead>
                    <tr>
                        <th>类型</th>
                        <th>已发放</th>
                        <th>已使用</th>
                        <th>已过期</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($money as $key=> $items)
                    <tr>
                        <td>{{$gift_cate[$key]->name}}</td>
                        <td>{{empty($items['0'])?'0.00':number_format($items['0'],2)}}</td>
                        <td>{{empty($items['1'])?'0.00':number_format($items['1'],2)}}</td>
                        <td>{{empty($items['2'])?'0.00':number_format($items['2'],2)}}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
@endsection
@section('scripts')
    <script>
        /**
         * 格式化时间
         *
         * @param now
         * @returns {string}
         */
        function formatDate(now) {
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }
        ;
    </script>
@endsection
